<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/core" prefix="c"%>
<%@ taglib uri="/tags/fmt" prefix="fmt"%>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript">
function validate(){
        var errors = "";
        var poNumber = document.getElementById('poNumber').value;
        if (poNumber == "") {
        	errors += ' <bean:message key="lable.plants.validation.priority"/>\n';
        }
        if( errors == "" ){
            return true;
        }else{
            alert( '<bean:message key="label.common.errors"/> : \n' + errors );
			return false;
        }        
    }
</script>

<html:form action="/addPoPlannedReals" onsubmit="return validate();" method="POST">
<input type="hidden" name="purchaseOrderId" value='<bean:write name="purchaseOrderView"  property="purchaseOrderId"/>'>
<input type="hidden" id="poNumberParameter" name="poNumberParameter" value='<bean:write name="poNumberParameter"/>'>
<table id="tabla" align="center" width="30%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
  <tr>
	<td colspan="4" class="titulocolumna" align="center">
		<bean:message key="label.transit.corn.table.title"/><br/>
		<bean:write name="purchaseOrderView"  property="purchaseOrderCode"/><bean:write name="purchaseOrderView"  property="postFix"/>
	</td>
  </tr>  
  <tr>
  	<td class="etiqueta" align="center">&nbsp;</td>  	
  	<td class="columnadatoNon" align="center"> <bean:message key="label.transit.corn.po.number"/> </td>
  	<td class="columnadatoNon" align="center"> <bean:message key="label.transit.corn.quantity"/> </td>
  	<td class="columnadatoNon" align="center"> <bean:message key="label.transit.corn.place"/> </td>
  </tr>
  <tr>
  	<td class="columnadatoNon">  		
  		<html:radio styleId="defaultRadio" property="number" value="number"/>
  	</td>  	
  	<td class="columnadatoNon" colspan="3" align="left">
  		<bean:message key="label.common.none"/>
  	</td>
  </tr>
  <logic:notEmpty name="transitCornList">
		<logic:iterate id="row" name="transitCornList" indexId="int_i">
			<tr class="<%=((int_i.intValue()%2)==0?"columnadatoPar":"columnadatoNon")%>">																			
				<td align="center">
					<bean:define id="numberValue"><bean:write name="row" property="poNumber"/></bean:define> 											
					<html:radio styleId="radioId" property="number" value="<%=numberValue%>" /> 						
				</td>										
				<td align="center"><bean:write name="row" property="poNumber"/></td>
				<td align="center"><bean:write name="row" property="quantity"/></td>
				<td align="center"><bean:write name="row" property="place"/></td>		
			</tr>
		</logic:iterate>
	</logic:notEmpty>
	<tr>
	<td colspan="4" align="center" class="columnadatoPar">
		<html:submit styleClass="boton"><bean:message key="label.common.save"/></html:submit>&nbsp;&nbsp;		
		<html:button styleClass="boton" property="backButton" onclick="location.href='listPurchaseProgramQuery.do';"><bean:message key="label.common.cancel"/></html:button>
		</td>
	</tr>
</table>
<br />
<br />
<script type="text/javascript">
	var defaultRadio = document.getElementById("defaultRadio");
	var selRadio = document.getElementById("radioId").value;
	var radioValue = document.getElementById("poNumberParameter").value;
	var size = document.PoPlannedRealsForm.radioId.length;	
	
	if(radioValue != ""){	 	
	 	for(var i=0; i < size; i++){	 		
	 		if(document.PoPlannedRealsForm.radioId[i].value == radioValue){
	 			document.PoPlannedRealsForm.radioId[i].checked=true;		
	 		}
	 	}	 		 		 	
	}else {		
		defaultRadio.checked=true;
	}	
</script>
</html:form>
